Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.HTTP = void 0;
var e = require("../@babel/runtime/helpers/classCallCheck"),
  t = require("../@babel/runtime/helpers/createClass"),
  r = function () {
    function r() {
      e(this, r)
    }
    return t(r, [{
        key: "request",
        value: function (e) {
          var t = this,
            r = e.url,
            o = e.data,
            s = void 0 === o ? {} :
            o,
            a = e.header,
            i = void 0 === a ? {} :
            a,
            d = e.method,
            n = void 0 === d ? "GET" : d,
            h = e.isShowLoading,
            l = void 0 === h || h,
            u = e.title,
            c = void 0 === u ? "加载中" : u,
            v = e.dealWithHasNoUserId,
            w = void 0 !== v && v;
          return new Promise((function (e, o) {
            t._request({
              resolve: e,
              reject: o,
              url: r,
              data: s,
              header: i,
              method: n,
              isShowLoading: l,
              title: c,
              dealWithHasNoUserId: w
            })
          }))
        }
      }, {
        key: "_request",
        value: function (e) {
          var t = this,
            r = e.resolve,
            o = e.reject,
            s = e.url,
            a = e.data,
            i = e.header,
            d = e.method,
            n = e.isShowLoading,
            h = e.title;
          e.dealWithHasNoUserId;
          n && wx.showLoading({
              title: h,
              mask: !0
            }),
            wx.request({
              url: s,
              method: d,
              data: a,
              header: i,
              success: function (e) {
                var s = e.statusCode.toString();
                if (s.startsWith("2"))
                  if (s.endsWith("0"))
                    r(e.data);
                  else {
                    o(e);
                    var a = e.data.msg || "出错了~";
                    t._show_error(a)
                  }
                else if (s.startsWith("4"))
                  o(e), t._show_error("客户端错误[".concat(s, "]"));
                else if (s.startsWith("5"))
                  o(e), t._show_error("服务端错误[".concat(s, "]"));
                else {
                  o(e);
                  var i = e.data.msg || "出错了~";
                  t._show_error(i)
                }
                n && wx.hideLoading()
              },
              fail: function (e) {
                o(e);
                var r = res.data.msg || "出错了~";
                t._show_error(r),
                  n && wx.hideLoading()
              }
            })
        }
      }, {
        key: "_show_error",
        value: function (e) {
          wx.showToast({
            title: e,
            icon: "none",
            duration: 2e3
          })
        }
      }]),
      r
  }
  ();
exports.HTTP = r;